// pages/filtrate/filtrate.js
var util = require('../../utils/util');
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: '', //传入时间
        date_month: '', //显示时间
        store_name: ['全部', '预约联系', '预约到店'],
        type: 0, //筛选
        information_list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var This = this;
        if (options != '')(
            This.setData({
                type: options.type
            })
        )
        var time = util.formatTime(new Date());
        var date_value = time.slice(0, 4) + "-" + time.slice(5, 7)
        var date_value_month = time.slice(0, 4) + "-" + time.slice(5, 7) 
        console.log(date_value)
        This.setData({
            date: date_value,
            date_month: date_value_month,
        })
        This.laoding();
    },
    bindDateChange: function(e) {
        var This = this;
        This.setData({
            information_list: []
        })
        var date_month = e.detail.value
        var year = date_month.slice(0, 4)
        var month = date_month.slice(5, 7)
        var date_time = year + "-" + month 
        This.setData({
            date_month: date_time,
            date: e.detail.value
        })
        This.laoding();
    },
    bindPickerChange(e) {
        console.log(e.detail.value)
        var This = this;
        This.setData({
            information_list: [],
            type: e.detail.value
        })
        This.laoding();
    },
    laoding() {
        var This = this;
        App._get('coach/callerdetail/get_reservation_contact_data', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            date: This.data.date,
            // store_id: 53,
            // openid: 1,
            // phone: 15612340001,
            // date: "2019-09",
        }, function(res) {
            if (res.status == 1) {
                This.setData({
                    information_list: res.list
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    filtrate_member_call(e) {
        wx.makePhoneCall({
            phoneNumber: e.target.id,
        })
    },
    no_store(e) {
        var This = this;
        App._get('callerdescribe/describeExit', {
            signature: str,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            describe_id: e.target.id,
            type: 2,
        }, function(res) {
            if (res.status == 1) {
                This.laoding();
            } else {
                wx.showToast({
                    title: res.error.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    go_store(e) {
        var This = this;
        App._get('callerdescribe/describeExit', {
            signature: str,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            describe_id: e.target.id,
            type: 1,
        }, function(res) {
            if (res.status == 1) {
                This.laoding();
            } else {
                wx.showToast({
                    title: res.error.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //详情
    detail(e) {
        var This = this;
        if (e.currentTarget.dataset.status == 2) {
            wx.navigateTo({
                url: '/pages/customer_information/customer_information?id=' + e.currentTarget.id + '&type=' + 2,
            })
        } else if (e.currentTarget.dataset.status == 1) {
            wx.navigateTo({
                url: '/pages/latent_maintenance/latent_maintenance?id=' + e.currentTarget.id + '&type=' + 1,
            })
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})